﻿using MiniFox.Components;
using MiniFox.Configurations;
using MiniFox.Net.Configurations;
using MiniFox.Net.Ftp;
using MiniFox.Net.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniFox.Net
{
    /// <summary>
    /// 
    /// </summary>
    public static class WebAdapterFactory
    {
        /// <summary>
        /// 
        /// </summary>
        static WebAdapterFactory()
        {
        }
        private static WebAdapterContainer _Container;
        /// <summary>
        /// 
        /// </summary>
        public static WebAdapterContainer Container
        {
            get
            {
                if (_Container == null)
                {
                    lock (typeof(WebAdapterContainer))
                    {
                        if (_Container == null)
                        {
                            try
                            {
                                if (ComponentFactory.IsRegistered<WebAdapterContainer>())
                                {
                                    _Container = ComponentFactory.GetComponent<WebAdapterContainer>();
                                }
                                else
                                {
                                    _Container = new DefaultWebAdapterContainer();
                                }
                            }
                            catch
                            {
                                _Container = new DefaultWebAdapterContainer();
                            }
                        }
                    }
                }
                return _Container;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static HttpAdapter GetHttpAdapterByName(string name)
        {
            var adapter = Container.GetHttpAdapterByName(name);
            return adapter;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static FtpAdapter GetFtpAdapterByName(string name)
        {
            var adapter = Container.GetFtpAdapterByName(name);
            return adapter;
        }

    }
}
